using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace CauBeTimMe.objects
{
    class Sprite
    {
        public event EventHandler Click = delegate { };
        protected Texture2D img;
        protected float timedelay = 0;
        protected float time = 0;
        private Vector2 Pos;
        private Boolean press;
        public Boolean isVisible = true;

        public Vector2 Location
        {
            set { Pos = value; }
            get { return Pos; }
        }

        public Sprite(Texture2D img)
        {
            this.img = img;
        }

        public void draw(SpriteBatch spBatch)
        {
            if (!isVisible) return;
            spBatch.Draw(img, Pos, Color.White);
        }

        public void update(GameTime gameTime)
        {
            if (!isVisible) return;
        }

        public Boolean isContain(int x, int y)
        {
            return true;
        }

        public void TouchEvent(TouchLocation touch)
        {
            if (!isVisible) return;
            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                    pressed(touch);
                    break;
                case TouchLocationState.Released:
                    release(touch);
                    break;
                case TouchLocationState.Moved:
                    moved(touch);
                    break;
            }
        }

        private void pressed(TouchLocation touch)
        {
            if (isContain((int)touch.Position.X, (int)touch.Position.Y))
            {
                press = true;
            }
        }

        private void release(TouchLocation touch)
        {
            if (isContain((int)touch.Position.X, (int)touch.Position.Y))
            {
                press = false;
                Click(this, new EventArgs());
            }
        }

        private void moved(TouchLocation touch)
        {
            if (isContain((int)touch.Position.X, (int)touch.Position.Y))
            {
                press = true;
            }
            else
            {
                press = false;
            }
        }

        protected void TouchEvent(GestureSample gesture)
        {
            if (!isVisible) return;
        }
    }
}
